"""
WSGI config for AutoRegister project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""

import os
import threading
from multiprocessing import Process
from django.core.wsgi import get_wsgi_application
from models.models import OltInfo
from tools.autoregister.autoregister import hwolt_run as run
from tools.autoregister.zte_autoregister import hwolt_run as zte
from tools.network import monitoring_state
from tools.checkRedis import dispose_redisdata

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'AutoRegister.settings')

application = get_wsgi_application()
telnet_host_list = list()
all_login_info = OltInfo.objects.filter(olt_ip='124.95.249.225')
for i in all_login_info:
    if i.olt_mode == '华为':
        telnet_host = threading.Thread(target=run, args=(i.olt_ip, i.olt_port, i.olt_account, i.olt_passwd))
    else:
        telnet_host = threading.Thread(target=zte, args=(i.olt_ip, i.olt_port, i.olt_account, i.olt_passwd))
    telnet_host_list.append(telnet_host)

for i in telnet_host_list:
    i.start()
print("***启动 ping监控 ***")
pro_ping = Process(target=monitoring_state)
pro_ping.start()
